package org.bzjj.bean.insert;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import org.apache.log4j.Logger;
import org.bzjj.log.MyLog;
import org.bzjj.sql.OracleCon;
import org.bzjj.tool.Tools;

public class VEH_IS_PRINTQUEUE {

	private static String print_insert = "insert into VEH_IS_PRINTQUEUE (LSH, JYLSH, JCXDH, JYJGBH, XH, HPHM, HPZL, CLSBDH, CLPP1, CLXH, SYR, DYLX, DYZL, GXRQ, DYZT, CGLSH, CGGLBM, FZJG, DYCS, JYW, YXQZ, BYZD1, BYZD2, BYZD3, BYZD4, BYZD5) values ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', to_date('%s', 'dd-mm-yyyy hh24:mi:ss'), '%s', '%s', '%s', '%s', %s, '%s', to_date('%s', 'dd-mm-yyyy'), '%s', %s, %s, %s, %s);";
	private static String lsh_query = "select * from VEH_IS_PRINTQUEUE t where lsh ='%s'";

	public static String getInsert(String lsh) {

		Connection connection = OracleCon.getDBonnect().getConnection();

		if (connection == null) {
			Logger logger = MyLog.getLog("VEH_IS_PRINTQUEUE");
			logger.error("连接建立失败");
			return null;
		}
		ResultSet result = null;
		Statement stmt = null;
		String rtn = "";
		try {
			stmt = connection.createStatement();
			result = stmt.executeQuery(String.format(lsh_query, lsh));
			while (result.next()) {
				rtn += String.format(print_insert, result.getString("LSH"),
						result.getString("JYLSH"), result.getString("JCXDH"),
						result.getString("JYJGBH"), result.getString("XH"),
						result.getString("HPHM"), result.getString("HPZL"),
						result.getString("CLSBDH"), result.getString("CLPP1"),
						result.getString("CLXH"), result.getString("SYR"),
						result.getString("DYLX"), result.getString("DYZL"),
						Tools.dateFormat(result.getTimestamp("GXRQ")),
						result.getString("DYZT"), result.getString("CGLSH"),
						result.getString("CGGLBM"), result.getString("FZJG"),
						result.getString("DYCS"), result.getString("JYW"),
						Tools.dateSimPleFormat(result.getTimestamp("YXQZ")),
						result.getString("BYZD1"), result.getString("BYZD2"),
						result.getString("BYZD3"), result.getString("BYZD4"),
						result.getString("BYZD5"));
			}
		} catch (SQLException e) {
			Logger logger = MyLog.getLog("VEH_IS_PRINTQUEUE");
			logger.error(e.getMessage());
		}
		try {
			result.close();
			stmt.close();
			connection.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}

		return rtn;
	}
	
	public static boolean exist(String lsh) {

		Connection connection = OracleCon.getDBonnect().getConnection();

		if (connection == null) {
			Logger logger = MyLog.getLog("VEH_IS_PRINTQUEUE");
			logger.error("连接建立失败");
			return false;
		}
		ResultSet result = null;
		Statement stmt = null;
		String rtn = null;
		try {
			stmt = connection.createStatement();
			result = stmt.executeQuery(String.format(lsh_query, lsh));
			while (result.next()) {
				rtn=result.getString("LSH");
			}
		} catch (SQLException e) {
			Logger logger = MyLog.getLog("VEH_IS_PRINTQUEUE");
			logger.error(e.getMessage());
		}
		try {
			result.close();
			stmt.close();
			connection.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}

		return rtn==null?false:true;
	}


}
